class Commoncode < ActiveRecord::Base
  validates_uniqueness_of :Code, :case_sensitive => false  
  validates_presence_of :Code, :Name, :EName, :InUse, :CodeLevel, :Type
  validates_length_of :Code, :within => 2..8

  def self.find_master_codes
    find(:all, :order => "code", :select => "Code, Name", :conditions =>[" Codelevel = 0"])
  end

  def self.find_detail_codes
    find(:all, :conditions =>["Codelevel > 0"])
  end

  def self.search(search)
    if search
      find(:all, :conditions => [" ParentCode = ?", "#{search}"])
    else
      find(:all, :conditions => ["Codelevel > 0"])
    end
  end
end
